from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
from rest_framework_simplejwt.views import TokenObtainPairView
from .permissions import IsOwnerOrReadOnly
from adminuser.serializers import UserRoleSerializers


class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
    def validate(self, attrs):
        data = super().validate(attrs)
        data['username'] = self.user.name

        data['id'] = self.user.id

        data['id'] = self.user.id

        roles=self.user.role.all()#获取用户的角色信息
        ser=UserRoleSerializers(roles,many=True)
        data['roles']=ser.data
        data['is_superuser']=self.user.is_superuser
        return data

class MyTokenObtainPairView(TokenObtainPairView):

    serializer_class = MyTokenObtainPairSerializer


